﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LazyKex.Syntatic;
using LazyKex.Semantic;

namespace LazyKex
{
    public class SyntaticLazyKex
    {

        private LazyKDislexic dislexic;
        private CodeGenerator codeGenerator;
        private SemanticLazyKex semantic;

       

        public SyntaticLazyKex(LazyKDislexic dislexic)
        {
            this.dislexic = dislexic;
            this.codeGenerator = new CodeGenerator();
            this.semantic = new SemanticLazyKex(codeGenerator);
        }

        public bool TryAnalyse()
        {
            try
            {
                while (dislexic.HasMoreTokens())
                {
                    dislexic.NextToken();
                    ExpressionSubMachine subMachine = new ExpressionSubMachine(dislexic, semantic);
                    if (!subMachine.Process())
                    {
                        return false;
                    }
                }

                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }
        }

        public string GetCode()
        {
            return codeGenerator.GetCode();
        }




    }

}
